import Vue from 'vue'
import App from './App.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import 'font-awesome/css/font-awesome.min.css';
import store from './store'
import { post, get, put, deletefn } from './assets/api/api.js'
import { downloadRequest } from './assets/api/download.js';
import { initMenu } from './assets/api/menu.js';

Vue.config.productionTip = false
Vue.use(ElementUI)
Vue.prototype.$post = post
Vue.prototype.$get = get
Vue.prototype.$put = put
Vue.prototype.$deletefn = deletefn
Vue.prototype.$downloadRequest = downloadRequest


router.beforeEach((to, from, next) => {

  if (window.sessionStorage.getItem('tokenStr')) {
    initMenu(router, store);
    console.log(12314)
    if(!window.sessionStorage.getItem("user")){
      return get("/login/info").then(res => {
        if(res){
          window.sessionStorage.setItem("user",JSON.stringify(res));
          store.commit('INIT_CURRENTAdmin',res);
          // next();
        }
      })
    }
    next();
  } else {
    if(to.path == '/'){
      next();
    }else {
      next('/?redirect=' + to.path);
    }
    
  }

})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
